package com.pets.springboot_petshop.mapper;

import com.pets.springboot_petshop.entity.Shoppingcart;
import com.pets.springboot_petshop.entity.Useraddress;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/15 上午11:45 周二
 * @Description: 数据访问层接口
 */
@Mapper
@Repository
public interface UseraddressMapper {
    //id查询
    @Select("SELECT * FROM useraddress WHERE id = #{id}")
    Useraddress select(int id);
    //user_id查询
    @Select("SELECT * FROM useraddress WHERE user_id = #{user_id}")
    List<Useraddress> selectuser_id(int user_id);
    //查询所有
    @Select("SELECT * FROM useraddress")
    List<Useraddress> findAll();
    //添加
    @Insert("insert into useraddress(name,user_id,address_line1,address_line2,phone,create_time,update_time)values(#{name},#{user_id},#{address_line1},#{address_line2},#{phone},now(),now());")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(Useraddress useraddress);
    //删除
    @Delete("delete from useraddress where id=#{id};")
    int delete(int id);
    //用户删除
    @Delete("delete from useraddress where  user_id=#{user_id} and id=#{id};")
    int deleteUser(Useraddress useraddress);
    //修改数据
    @Update("UPDATE useraddress SET name=#{name},address_line1=#{address_line1},address_line2=#{address_line2},phone=#{phone},update_time=now() where id= #{id};")
    int update(Useraddress useraddress);
}
